﻿using IDAL;

namespace DAL
{
    public class rkdal<T>:IRKDAL<T> where T : class
    {
        public rkdal(MyDBcontext my)
        {
            My = my;
        }

        public MyDBcontext My { get; }

        public async Task<int> AddAsync(T t)
        {
           My.Set<T>().AddAsync(t);
           return await My.SaveChangesAsync();
        }

        public async Task<int> AddRangeAsync(List<T> list)
        {
            My.Set<T>().AddRangeAsync(list);
            return await My.SaveChangesAsync();
        }

        public async Task<int> DeleteAsync(T t)
        {
            My.Set<T>().Remove(t);
            return await My.SaveChangesAsync();
        }

        public async Task<int> DeleteRangeAsync(List<T> list)
        {
            My.Set<T>().RemoveRange(list);
            return await My.SaveChangesAsync();
        }

        public IQueryable<T> GetAll()
        {
            return My.Set<T>();
        }

        public async Task<int> UpdateAsync(T t)
        {
            My.Set<T>().Update(t);
            return await My.SaveChangesAsync();
        }

        public async Task<int> UpdateRangeAsync(List<T> list)
        {
            My.Set<T>().UpdateRange(list);
            return await My.SaveChangesAsync();
        }
    }
}
